/*
 * @Author: hu_binbin
 * @Date: 2021-07-12 09:44:50
 * @LastEditTime: 2021-08-02 09:47:44
 * @Description: 二维码扫描
 */
import {Dialog} from 'vant'

export function scan() {
	return new Promise((resolve, reject) => {
		console.log("barcodeScanner=============")
		console.log(barcodeScanner)
		barcodeScanner.scan(
			function(result){
				console.log("We got a barcode\n" +
					"ResultText: " + result.text + "\n" +
					"Format: " + result.format + "\n" +
					"Cancelled: " + result.cancelled + "\n" +
					"TYPE: " + result.typeObj);
				if (result.cancelled) {
					Dialog.alert({
						title: '提示',
						message: '没有获取到二维码信息'
					})
				} else {
					console.log(result)
					resolve(result)
				}
			},
			function(error){
				console.log("scan ===== error")
				Dialog.alert({
					title: '提示',
					message: '扫描失败，请联系管理员'
				})
				reject(error)
			}

		)
	})
}


export default {
	scan
}
